#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main() {
	char s[50];
	gets(s);
	int x;
	sscanf(s, "%d", &x);
	while (x--) {
		gets(s);
		char *p;
		for (p = s + strlen(s) - 1; p != s; p--)
			if (isalpha(*p))
				putchar(*p);
		if (isalpha(*p))
			putchar(*p);
		putchar('\n');
	}
	return 0;
}
